package com.tshopping.controller;

import com.tshopping.service.GoodsCollectionService;
import com.tshopping.util.ResponseData;
import com.tshopping.util.TimeProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @name: GoodsCollectionController
 * @description: 收藏商品页面控制器
 * @author: Jackeys
 * @date: 2021-01-29 15:39
 */
@RestController
@RequestMapping("/GoodsCollectionController")
@CrossOrigin
public class GoodsCollectionController {

    @Autowired
    private GoodsCollectionService goodsCollectionService;

    @PostMapping(value = "/addGoodsCollection")
    /**
     * @description 用户添加商品收藏
     * @Param: user
     * @Param: goods
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 15:42
     */
    public ResponseData addGoodsCollection(int user, int goods) throws ParseException {
        return goodsCollectionService.addGoodsCollection(user, goods, TimeProvider.getTime());
    }

    @PostMapping(value = "/deleteGoodsCollectionById")
    /**
     * @description 用户取消商品收藏
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 15:44
     */
    public ResponseData deleteGoodsCollectionById(int id) {
        return goodsCollectionService.deleteGoodsCollectionById(id);
    }

    @PostMapping(value = "/getGoodsCollectionList")
    /**
     * @description 用户获取收藏商品
     * @Param: user
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 15:45
     */
    public ResponseData getGoodsCollectionList(int user, int currentPage) {
        return goodsCollectionService.selectGoodsCollectionList(user, currentPage);
    }

    @PostMapping(value = "/isGoodsCollected")
    /**
     * @description 处理判断用户是否收藏商品
     * @Param: goods
     * @Param: user
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 15:57
     */
    public ResponseData isGoodsCollected(int goods, int user) {
        return goodsCollectionService.selectCount(goods, user);
    }

    @PostMapping(value = "/deleteGoodsCollection")
    /**
     * @description 处理用户取消商品收藏
     * @Param: user
     * @Param: goods
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 16:32
     */
    public ResponseData deleteGoodsCollection(int user, int goods) {
        return goodsCollectionService.deleteGoodsCollectionByUserAndGoods(user, goods);
    }
}
